#ifndef __COMPONENT_FLY_AWAY_BEHAVIOR_H__
#define __COMPONENT_FLY_AWAY_BEHAVIOR_H__

#include "ComponentBehavior.hpp"
#include "Engine/MathUtils.hpp"
#include "Engine/Vector2.hpp"
#include "entt/entity/entity.hpp"

#include "EasyMachine.hpp"

using namespace PocketSurvival::Engine;

namespace PocketSurvival
{
    struct ComponentCreature;
    struct ComponentBody;
    struct ComponentPathfinding;

    struct ComponentMoveAwayBehavior : public ComponentBehavior
    {
    protected:
        enum class MachineState
        {
            Inactive,
            Move
        };

        class StateMachine : public EasyMachine<MachineState>
        {
        protected:
            ComponentMoveAwayBehavior * m_moveAway;
        public:
            StateMachine(ComponentMoveAwayBehavior *moveAway);

            virtual void enter() override;
            virtual void update(float dt) override;
            virtual void leave() override;
        };

    protected:
        float m_isFast;
        float m_importanceLevel = 0.0f;
        StateMachine *m_stateMachine;
        entt::entity m_targetEntity = entt::null;

    public:
        ComponentCreature *componentCreature;
        ComponentPathfinding *componentPathfinding;

        ComponentMoveAwayBehavior() = default;
        ~ComponentMoveAwayBehavior();

        virtual float getImportanceLevel() override;

        virtual void update(float dt) override;
        virtual void load(const nlohmann::json &jsonData) override;
        virtual const std::string &getName() const override;
        static const std::string &GetName();
    };
}

#endif
